<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@page import="java.util.ArrayList" %>
<%@page import="com.bss.command.PatientCommand" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%
	/*ArrayList<String> firstName=(ArrayList<String>)session.getAttribute("firstname");
	ArrayList<String> middleName=(ArrayList<String>)session.getAttribute("middlename");
	ArrayList<String> lastName=(ArrayList<String>)session.getAttribute("lastname");
	ArrayList<Integer> patientId=(ArrayList<Integer>)session.getAttribute("patientId");
	ArrayList<Integer> checklist=(ArrayList<Integer>)session.getAttribute("patientId");*/
	
	ArrayList<String> firstName=PatientCommand.loadFirstNames();
	ArrayList<String> middleName=PatientCommand.loadMiddleNames();
	ArrayList<String> lastName=PatientCommand.loadLastNames();
	ArrayList<Integer> patientId=PatientCommand.loadID();
	ArrayList<Integer> checklist=PatientCommand.loadID();
	
	
	
	
	String status="";
	String str1=request.getParameter("q").toString();

	String status1="<table bgcolor='#202020' width='300'  border='1' cellspacing='0' cellpadding='0' align='center'>"+
	"<tr>"+
	"<td width='85'>"+
		"<h5>PATIENT ID</h5>"+
	"</td>"+
	"<td align='center'>"+
		"<h5>PATIENT NAME</h5>"+
	"</td>"+
"</tr>";

	String status2 = "</table>" ;
	
	if(str1=="" || str1==null)
	{
		
		for(int i=0;i<patientId.size();i++)
		{
			status+="<tr>"+
			"<td width='85' align='center'>"+
			"<a href='editpatient.jsp?id="+patientId.get(i)+"'>"+patientId.get(i)+"</a>"+
			"</td>"+
			"<td align='center'>"+
			firstName.get(i).toUpperCase()+"  "+middleName.get(i).toUpperCase()+" "+lastName.get(i).toUpperCase()+" "+
			"</td>"+
			"<td align='center'>"+
			"<a href='editpatient.jsp?id="+patientId.get(i)+"'> EDIT </a>"+
			"</td>"+
			"</tr>";
										
		}
		
		//response.getWriter().write(status);
	}	
	else
	{
	
		str1=str1.toUpperCase();
	
		for(int i=0;i<patientId.size();i++)
		{
			String str=firstName.get(i).toUpperCase();
			if(str.startsWith(str1)==true)
			{
				if(checklist.get(i)!=0)
				{
					
					status+="<tr>"+
					"<td width='85' align='center'>"+
					"<a href='editpatient.jsp?id="+patientId.get(i)+"'>"+patientId.get(i)+"</a>"+
					"</td>"+
					"<td align='center'>"+
					firstName.get(i).toUpperCase()+"  "+middleName.get(i).toUpperCase()+" "+lastName.get(i).toUpperCase()+" "+
					"</td>"+
					"<td align='center'>"+
					"<a href='editpatient.jsp?id="+patientId.get(i)+"'> EDIT </a>"+
					"</td>"+
					"</tr>";
					
					checklist.set(i,0);			
				}
			}
		}
		
		for(int i=0;i<patientId.size();i++)
		{
			String str=lastName.get(i).toUpperCase();
					
			if(str.startsWith(str1)==true)
			{
				if(checklist.get(i)!=0)
				{	
					
					status+="<tr>"+
					"<td width='85' align='center'>"+
					"<a href='editpatient.jsp?id="+patientId.get(i)+"'>"+patientId.get(i)+"</a>"+
					"</td>"+
					"<td align='center'>"+
					firstName.get(i).toUpperCase()+"  "+middleName.get(i).toUpperCase()+" "+lastName.get(i).toUpperCase()+" "+
					"</td>"+
					"<td align='center'>"+
					"<a href='editpatient.jsp?id="+patientId.get(i)+"'> EDIT </a>"+
					"</td>"+
					"</tr>";
					
					checklist.set(i,0);			
				}
			}
		}

		for(int i=0;i<patientId.size();i++)
		{
			String str=middleName.get(i).toUpperCase();
		
			if(str.startsWith(str1)==true)
			{
				if(checklist.get(i)!=0)
				{
					
					status+="<tr>"+
					"<td width='85' align='center'>"+
					"<a href='editpatient.jsp?id="+patientId.get(i)+"'>"+patientId.get(i)+"</a>"+
					"</td>"+
					"<td align='center'>"+
					firstName.get(i).toUpperCase()+"  "+middleName.get(i).toUpperCase()+" "+lastName.get(i).toUpperCase()+" "+
					"</td>"+
					"<td align='center'>"+
					"<a href='editpatient.jsp?id="+patientId.get(i)+"'> EDIT </a>"+
					"</td>"+
					"</tr>";
					
					checklist.set(i,0);	
					
				}
			}
		}
	
	}
	response.getWriter().write(status1+status+status2);
	
%>
</body>
</html>